package com.qianfeng.tiantian_banjia.adapter;

import java.util.List;

import org.w3c.dom.Text;

import android.content.Context;
import android.graphics.Bitmap;
import android.util.Log;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import com.lidroid.xutils.BitmapUtils;
import com.qianfeng.tiantian_banjia.R;
import com.qianfeng.tiantian_banjia.bean.Goods;
import com.qianfeng.tiantian_banjia.utils.AppContasnts;
import com.qianfeng.tiantian_banjia.utils.AsyncImageLoader;
import com.qianfeng.tiantian_banjia.utils.AsyncImageLoader.ImageLoaderlistener;

public class MyListviewAdapter extends MyBaseAdpter<Goods> {

	private BitmapUtils bitmapUtils;

	public MyListviewAdapter(Context context, List<Goods> list,
			AsyncImageLoader loader) {
		super(context, list, loader);
		// TODO Auto-generated constructor stub
		bitmapUtils = new BitmapUtils(context);
	}

	@Override
	public View getConvertView(int position, View convertView, ViewGroup parent) {
		// TODO Auto-generated method stub
		ViewHolder vh;
		if (convertView == null) {
			convertView = inflater.inflate(R.layout.itemlist_goods, parent,
					false);
			vh = new ViewHolder(convertView);
			convertView.setTag(vh);

		} else {
			vh = (ViewHolder) convertView.getTag();
		}
		Goods goods = list.get(position);
		if (list.get(position) != null) {

			vh.txtTile.setText(goods.getCustom_titles());
			vh.txtPrice.setText(goods.getCustom_price() + "");
			vh.txtDesc.setText(goods.getCustom_price_desc());
			vh.txtLaiyuan.setText(goods.getCustom_product_business());
			vh.txtUserLove.setText(goods.getUser_like());

		}
		Log.i("123",
				"path---goods.getCustom_image()+" + goods.getCustom_image());
		final String path = goods.getCustom_image();
		bitmapUtils.display(vh.imgGoods, path);

		return convertView;
	}

	public class ViewHolder {
		public ImageView imgGoods;
		public TextView txtTile;
		public TextView txtPrice;
		public TextView txtDesc;
		public TextView txtLaiyuan;
		public TextView txtUserLove;
		public ImageView image;

		public ViewHolder(View convertView) {
			this.imgGoods = (ImageView) convertView
					.findViewById(R.id.img_itemlist_goods);
			this.txtTile = (TextView) convertView
					.findViewById(R.id.title_itemsgoods);
			this.txtPrice = (TextView) convertView
					.findViewById(R.id.price_itemsgoods);
			this.txtDesc = (TextView) convertView
					.findViewById(R.id.desc_itemsgoods);
			this.txtLaiyuan = (TextView) convertView
					.findViewById(R.id.laiyuan_itemsgoods);
			this.txtUserLove = (TextView) convertView
					.findViewById(R.id.userLove_itemsgoods);

		}

	}

}
